package gatperdut.chato.core.messaging.replies;

import gatperdut.chato.core.ChatoServer;
import gatperdut.chato.core.messaging.grammar.messinfo.ListPlayersInfo;
import gatperdut.chato.model.Chato.Player.Player;

import org.json.simple.JSONArray;

public class ListPlayersReply extends Reply {

    public ListPlayersReply( ListPlayersInfo listPlayersInfo, ChatoServer chatoServer ) {
        super( listPlayersInfo, chatoServer );
    }

    @Override
    public String send() {
        Player[] allPlayersArray = getPlayersPackager().toArray( getChatoServer().getEntityHandler().getRegisteredPlayers().toArray() );
        JSONArray allPlayersJA = getPlayersPackager().packageAll( allPlayersArray );
        return allPlayersJA.toJSONString();
    }

    @Override
    public ListPlayersInfo getMessageInfo() {
        return (ListPlayersInfo) super.getMessageInfo();
    }

}
